﻿<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="EditAdministratorGroup.aspx.cs" Inherits="Cms.Web.UI.Admin.EditAdministratorGroup" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" language="javascript">
        //<![CDATA[
        function initList() {
            var spans = document.getElementById("tdPermissionContainer").getElementsByTagName("span");
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].parentNode.tagName == "LI") {
                    iLib.Dom.AddListener(spans[i], "click", function (e) {
                        e = e || window.event;
                        var span = e.target || e.srcElement;
                        var input = span.previousSibling;
                        var li = span.parentNode;
                        input.checked = !(input.checked) && !input.disabled;
                        updateSubPermissions(li, input.checked);
                    });
                }
            }
            var inputs = document.getElementById("tdPermissionContainer").getElementsByTagName("input");
            for (var i = 0; i < inputs.length; i++) {
                iLib.Dom.AddListener(inputs[i], "click", function (e) {
                    e = e || window.event;
                    var input = e.target || e.srcElement;
                    var li = input.parentNode;
                    updateSubPermissions(li, input.checked);
                });
            }
        }

        function updateSubPermissions(li, permissionEnabled) {
            var uls = li.getElementsByTagName("ul");
            var ul = null;
            for (var n = 0; n < uls.length; n++) {
                if (uls[n].parentNode == li) {
                    ul = uls[n];
                }
            }
            if (ul != null) {
                var inputs = ul.getElementsByTagName("input");
                if (permissionEnabled) {
                    for (var n = 0; n < inputs.length; n++) {
                        //Enable only the sub permissions directly below
                        if (inputs[n].parentNode.parentNode == ul) {
                            inputs[n].disabled = false;
                        }
                    }
                }
                else {
                    for (var n = 0; n < inputs.length; n++) {
                        //Disable and uncheck all underlying permissions
                        inputs[n].checked = false;
                        inputs[n].disabled = true;
                    }
                }
            }
        }

        function collectSelectedPermissions() {
            var hidSelectedPermissions = document.getElementById("ctl00_body_hidSelectedPermissions");
            hidSelectedPermissions.value = "";
            var inputs = document.getElementById("tdPermissionContainer").getElementsByTagName("input");
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].checked && !inputs[i].disabled) {
                    hidSelectedPermissions.value += "," + inputs[i].id.substring(3);
                }
            }
            hidSelectedPermissions.value = hidSelectedPermissions.value.substring(1);
        }
        //]]>
    </script>
    <style type="text/css">
        #tdPermissionContainer ul
        {
            list-style-type: none;
            margin-top: 0px;
            margin-left: -40px;
        }

        #tdPermissionContainer ul ul
        {
            margin-left: -10px;
        }

        #tdPermissionContainer input
        {
            vertical-align: middle;
        }

        #tdPermissionContainer span
        {
            display: inline-block;
            vertical-align: middle;
            padding-left: 3px;
            cursor: pointer;
            padding-top: 1px;            
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="buttons" runat="server">
    <asp:LinkButton ID="lbSave" runat="server" OnClientClick="collectSelectedPermissions();" OnClick="lbSave_Click" CssClass="orangeButton"><span><span><img src="Admin/Img/icons/disk.png" alt="" /><span><cms:LocalizedLiteral ID="llSave" runat="server" /></span></span></span></asp:LinkButton>
    <a href="Admin/AdministratorGroups.aspx" class="orangeButton"><span><span><img src="Admin/Img/icons/delete.png" alt="" /><span><cms:LocalizedLiteral ID="llCancel" runat="server" /></span></span></span></a>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="body" runat="server">
    <asp:Literal ID="litIcon" runat="server" Visible="false" Text="Admin/Img/Icons/group_edit.png" />
    <input type="hidden" id="hidSelectedPermissions" runat="server" />
    <table class="editForm">
        <tr>
            <td><cms:LocalizedLiteral ID="llName" runat="server" />:</td>
            <td><asp:TextBox ID="txtName" runat="server" /></td>
        </tr>
        <tr>
            <td><cms:LocalizedLiteral ID="llDefaultPageAccess" runat="server" />:</td>
            <td>
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td style="padding: 0px;"><asp:RadioButton ID="rbAllow" runat="server" GroupName="DefaultPageAccess" /></td>
                        <td onclick="document.getElementById('ctl00_body_rbAllow').checked = true;"><cms:LocalizedLiteral ID="llAllow" runat="server" /></td>
                        <td style="padding: 0px;"><asp:RadioButton ID="rbDeny" runat="server" GroupName="DefaultPageAccess" /></td>
                        <td onclick="document.getElementById('ctl00_body_rbDeny').checked = true;"><cms:LocalizedLiteral ID="llDeny" runat="server" /></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td><cms:LocalizedLiteral ID="llDefaultCustomAdminPageAccess" runat="server" />:</td>
            <td>
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td style="padding: 0px;"><asp:RadioButton ID="rbAllowCustomAdminPages" runat="server" GroupName="DefaultCustomAdminPageAccess" /></td>
                        <td onclick="document.getElementById('ctl00_body_rbAllowCustomAdminPages').checked = true;"><cms:LocalizedLiteral ID="llAllowCustomAdminPages" runat="server" /></td>
                        <td style="padding: 0px;"><asp:RadioButton ID="rbDenyCustomAdminPages" runat="server" GroupName="DefaultCustomAdminPageAccess" /></td>
                        <td onclick="document.getElementById('ctl00_body_rbDenyCustomAdminPages').checked = true;"><cms:LocalizedLiteral ID="llDenyCustomAdminPages" runat="server" /></td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr valign="top">
            <td><cms:LocalizedLiteral ID="llPermissions" runat="server" />:</td>
            <td id="tdPermissionContainer"><asp:Literal ID="litPermissions" runat="server" /></td>
        </tr>
    </table>
    <script language="javascript">
        iLib.Dom.AddListener(window, "load", initList);
    </script>
</asp:Content>
